/**
 * @file ThreadPool.hh
 * @author zziywang (zziywang@163.com)
 * @brief { life is too short to learn cpp! }
 * @version 1.0
 * @date 2022-05-08
 *
 * @copyright Copyright (c) 2022
 *
 */

#include "TaskQue.hh"
#include "Thread.hh"
#include <memory>
#include <vector>
using std::unique_ptr;
using std::vector;

namespace snow
{

class ThreadPool
{
public:
    ThreadPool(size_t threadNum, size_t queSize);
    ~ThreadPool();

    void start();
    void stop();

    void addTask(const Task &task);

private:
    Task getTask();
    void CallBack(); // 注册给子线程，取任务执行

private:
    size_t threadNum_;
    size_t queSize_;
    vector<unique_ptr<Thread>> threads_; // 线程池数组，unique_ptr托管线程对象
    TaskQue taskQue_;
    bool isExit_;
};

} // namespace snow